<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/resources/template/template.xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form id="form">
            <h:panelGroup id="panelError" 
                          rendered="#{shiftFingerPrintAnalysisController.errorMessage ne null and shiftFingerPrintAnalysisController.errorMessage.size()!=0}"
                          style="background-color: yellow; color: red; display: block; margin: 2px; border: 1px solid red; padding: 3px; width: 95%;" >
                <ui:repeat var="mes"
                           value="#{shiftFingerPrintAnalysisController.errorMessage}" >
                    <p:outputLabel value="#{mes}" /><br/>
                </ui:repeat>               
            </h:panelGroup>
            <h:panelGrid columns="2" styleClass="alignTop" style="width: 100%;" >
                <p:panel>
                    <h:panelGrid columns="2">
                        <h:outputLabel value="From Date"/>
                        <p:calendar id="frmDate" 
                                    value="#{shiftFingerPrintAnalysisController.fromDate}"
                                    pattern="dd MMMM yyyy" />
                        <h:outputLabel value="To Date"/>
                        <p:calendar id="toDate" 
                                    value="#{shiftFingerPrintAnalysisController.toDate}" 
                                    pattern="dd MMMM yyyy" />
                        <h:outputLabel value="Roster"/>
                        <p:selectOneMenu id="roster" value="#{shiftFingerPrintAnalysisController.roster}">
                            <f:selectItem itemLabel="Select Roster"/>
                            <f:selectItems value="#{rosterController.items}" 
                                           var="r" itemLabel="#{r.name}" itemValue="#{r}"/>
                            <f:ajax event="change" execute="@this" render="lst" 
                                    listener="#{shiftFingerPrintAnalysisController.selectRosterLstener()}" />

                        </p:selectOneMenu>
                        <h:panelGroup>
                            <p:commandButton value="Fill"
                                             process="@this frmDate toDate roster"
                                             update="lst"
                                             actionListener="#{shiftFingerPrintAnalysisController.makeTableNull()}"
                                             action="#{shiftFingerPrintAnalysisController.createShiftTable()}" 
                                             onclick="onSubmitButton();" /> 

                            <p:commandButton value="Fill Additional Only"
                                             process="@this frmDate toDate roster"
                                             update="lst"
                                             actionListener="#{shiftFingerPrintAnalysisController.makeTableNull()}"
                                             action="#{shiftFingerPrintAnalysisController.createShiftTableAdditional()}" 
                                             onclick="onSubmitButton();" /> 
                        </h:panelGroup>

                        <p:commandButton value="SAVE"
                                         process="lst"
                                         update="lst"
                                         action="#{shiftFingerPrintAnalysisController.save()}" 
                                         onclick="onSubmitButton();"/>
                    </h:panelGrid>

                    <p:commandButton value="Reset and Fill"
                                     process="@this frmDate toDate roster"
                                     update="lst"
                                     actionListener="#{shiftFingerPrintAnalysisController.makeTableNull()}"
                                     action="#{shiftFingerPrintAnalysisController.createShiftTableReset()}" 
                                     onclick="onSubmitButton();" 
                                     style="float: right;"/>
                </p:panel>

                <p:panel header="Links" style="float: right;" >
                    <p:panelGrid columns="2" styleClass="alignTop" >
                        <p:commandLink ajax="false" value="Roster Table" 
                                       action="/hr/hr_shift_table" 
                                       actionListener="#{shiftFingerPrintAnalysisController.toShiftTableController}"></p:commandLink>                       

                    </p:panelGrid>
                </p:panel>
            </h:panelGrid>

            <p:dataGrid  id="lst" columns="1" var="data"
                         value="#{shiftFingerPrintAnalysisController.shiftTables}" >
                <p:dataTable value="#{data.staffShift}" var="sts" rowIndexVar="i"
                             rowStyleClass="#{sts.shift.dayType eq 'DayOff'
                                              or sts.shift.dayType eq 'SleepingDay' ? 'highLight2':null}">
                    <f:facet name="header">
                        <h:outputLabel value="#{data.date}" >
                            <f:convertDateTime pattern="dd MM yyyy"/>
                        </h:outputLabel>
                    </f:facet>
                    <p:column headerText="No" styleClass="singleLine">
                        <h:outputLabel value="#{i+1}" />
                    </p:column>
                    <p:column headerText="Shift Name" styleClass="singleLine">
                        <h:outputLabel id="lblShift"  value="#{sts.shift.name}" />
                        <p:tooltip for="lblShift" >
                            <h:outputLabel value="#{sts.shift.id}" />
                        </p:tooltip>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Shift Duration"/>
                        </f:facet>
                        <h:outputLabel value="#{sts.shift.durationMin}"/>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Staff Code"/>
                        </f:facet>
                        <h:outputLabel value="#{sts.staff.code}"/>
                    </p:column> 

                    <p:column headerText="ID" styleClass="singleLine" >
                        <h:outputLabel value="#{sts.id}" />
                    </p:column>
                    <p:column headerText="Leave/Replace" styleClass="singleLine">                       
                        <h:outputLabel value="#{sts.leaveType}"  />                     
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Staff Name"/>
                        </f:facet>
                        <h:outputLabel value="#{sts.staff.person.name}"/>

                    </p:column> 
                    <p:column>
                        <f:facet name="header">
                            <h:outputLabel value="Staff Code"/>
                        </f:facet>
                        <h:outputLabel value="#{sts.staff.code}"/>
                    </p:column>     

                    <p:column headerText="Starting Record Frm Attendence"> 

                        <h:panelGroup rendered="#{sts.previousStaffShift eq null}" >        
                            <h:panelGroup  >
                                <p:selectOneMenu converter="fingerPrintRecordCon" value="#{sts.startRecord}"  > 
                                    <f:selectItem itemLabel="Select"/>
                                    <f:selectItems value="#{sts.fingerPrintRecordList}" var="i"
                                                   itemLabel="#{i.timeLabel}" itemValue="#{i}" />
                                    <f:ajax event="change" execute="@this" render="strRc"
                                            listener="#{shiftFingerPrintAnalysisController.fingerPrintSelectListenerStartRecord(sts)}"/>
                                </p:selectOneMenu>
                            </h:panelGroup>

                        </h:panelGroup>
                        <h:outputLabel value="Previous" rendered="#{sts.previousStaffShift ne null}"/>
                    </p:column>

                    <p:column headerText="E">
                        <h:outputLabel value="#{sts.previousStaffShift}" ></h:outputLabel>
                    </p:column>

                    <p:column headerText="Ending Record Frm Attendence">
                        <h:panelGroup rendered="#{sts.nextStaffShift eq null}">
                            <h:panelGroup >                           
                                <p:selectOneMenu converter="fingerPrintRecordCon" value="#{sts.endRecord}">  
                                    <f:selectItem itemLabel="Select"/>
                                    <f:selectItems value="#{sts.fingerPrintRecordList}" var="i" itemLabel="#{i.timeLabel}"  itemValue="#{i}" />
                                    <f:ajax event="change" execute="@this" render="endRc "
                                            listener="#{shiftFingerPrintAnalysisController.fingerPrintSelectListenerEndRecord(sts)}"/>
                                </p:selectOneMenu>   
                            </h:panelGroup>

                        </h:panelGroup>
                        <h:outputLabel value="Next" rendered="#{sts.nextStaffShift ne null}"/>
                    </p:column>

                    <p:column headerText="Starting Record Varified">

                        <h:panelGroup id="strRc"       >
                            <h:panelGroup rendered="#{sts.startRecord ne null}" >
                                <p:calendar                                   
                                    value="#{sts.startRecord.recordTimeStamp}" 
                                    pattern="dd MM yy hh mm ss a"  >                           
                                    <p:ajax event="click" process="@this" update="@this"
                                            listener="#{shiftFingerPrintAnalysisController.listenStart(sts)}"/>
                                </p:calendar>
                                <h:panelGroup rendered="#{sts.startRecord.allowedExtraDuty}">
                                    <h:outputLabel value="Extra"/>
                                </h:panelGroup>
                            </h:panelGroup>
                            <h:outputLabel value="No Records" rendered="#{sts.startRecord eq null}"/>
                        </h:panelGroup>

                    </p:column>

                    <p:column headerText="Ending Record  Varified">

                        <h:panelGroup id="endRc">

                            <h:panelGroup rendered="#{sts.endRecord ne null}">
                                <p:calendar                                    
                                    value="#{sts.endRecord.recordTimeStamp}" 
                                    pattern="dd MM yy hh mm ss a" >          
                                    <p:ajax event="click" process="@this" update="@this"
                                            listener="#{shiftFingerPrintAnalysisController.listenEnd(sts)}"/>
                                </p:calendar>                             
                                <h:panelGroup rendered="#{sts.endRecord.allowedExtraDuty}">
                                    <h:outputLabel value="Extra"/>
                                </h:panelGroup>
                            </h:panelGroup> 
                            <h:outputLabel value="No Records" rendered="#{sts.endRecord eq null}"/>
                        </h:panelGroup>
                    </p:column>


                </p:dataTable>  
            </p:dataGrid>


        </h:form>  



    </ui:define>



</ui:composition>
